﻿using Abp.Linq.Extensions;
using AutoMapper.QueryableExtensions;
using Microsoft.EntityFrameworkCore;
using NetCore.Dtos;
using NetCore.Entities.Projects;
using NetCore.Interfaces;
using NetCore.Projects.Dtos;
using NetCore.Services;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;

namespace NetCore.Projects
{
    /// <summary>
    /// 项目附件
    /// </summary>
    [Description("项目附件")]
    public class ProjectAttachmentAppService : BaseNetCoreAppService<ProjectAttachment>, IProjectAttachmentAppService
    {
        public ProjectAttachmentAppService(INetCoreRepository<ProjectAttachment> baseRepository) : base(baseRepository)
        {
        }

        public async Task<List<ProjectAttachmentDto>> GetProjectAttachments(InputIdNullDto input)
        {
            var result = await BaseRepository.GetAll()
                .WhereIf(input.Id.HasValue, m => m.ProjectId == input.Id)
                .OrderByDescending(n => n.Order)
                .ProjectTo<ProjectAttachmentDto>()
                .ToListAsync();
            return result;
        }
    }
}
